/**
 * @author:albert
 */
package com.bkbw.live.battle.business;

import java.lang.reflect.Constructor;
import java.util.HashMap;

import com.bkbw.live.battle.business.behaviors.BulletMoveBehavior;


public class BehaviorFactory {
	
	protected HashMap<String, Class> behaviorLib = new HashMap<String, Class>();
	protected static BehaviorFactory instance = new BehaviorFactory();
	
	public static BehaviorFactory getInstance()
	{
		return instance;
	}
	
	private BehaviorFactory()
	{
		behaviorLib.put("BulletMoveBehavior", BulletMoveBehavior.class);
	}
	
	public BehaviorBase createBehavior(String behaviorClass, HashMap<String, Object> param) 
	{
		BehaviorBase behavior;
		try {
			Class[] paramType = new Class[]{HashMap.class};
			//Constructor constructor = Class.forName(behaviorClass).getConstructor(paramType);
			Constructor constructor = behaviorLib.get(behaviorClass).getConstructor(paramType);
			behavior = (BehaviorBase)constructor.newInstance(param);
			return behavior;
		}
		catch (Exception e) {
			return null;
		}
	}
}
